package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.EmployeeWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.user.qo.*;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description: 员工控制类
* @author  Yang
* date: 2021-6-24
* time: 15:48:45
*/
@RestController
@RequestMapping("/employee")
@Slf4j
public class EmployeeController extends BaseController{

    @Resource
    private EmployeeWebService employeeWebService;


    /**
     * 新增员工
     * @param addEmployeeQo
     * @return
     */
    @PostMapping("/addEmployee")
    public PlatformResult addEmployee(@Validated @RequestBody AddEmployeeQo addEmployeeQo){
        try {
            employeeWebService.addEmployee(addEmployeeQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[EmployeeController]---addEmployee--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---addEmployee--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 修改员工
     * @param editEmployeeQo
     * @return
     */
    @PostMapping("/editEmployee")
    public PlatformResult editEmployee(@Validated @RequestBody EditEmployeeQo editEmployeeQo){
        try {
            employeeWebService.editEmployee(editEmployeeQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[EmployeeController]---editEmployee--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---editEmployee--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 员工列表
     * @param employeeListQo
     * @return
     */
    @PostMapping("/employeeList")
    public PlatformResult employeeList(@Validated @RequestBody EmployeeListQo employeeListQo){
        try {
            return PlatformResult.success(employeeWebService.employeeList(employeeListQo));
        } catch (BusinessException e) {
            log.error("[EmployeeController]---employeeList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---employeeList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 员工入职
     * @param empInductionQo
     * @return
     */
    @PostMapping("/empInduction")
    public PlatformResult empInduction(@Validated @RequestBody EmpInductionQo empInductionQo){
        try {
            employeeWebService.empInduction(empInductionQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[EmployeeController]---empInduction--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---empInduction--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 员工离职
     * @param empDimissionQo
     * @return
     */
    @PostMapping("/empDeparture")
    public PlatformResult empDeparture(@Validated @RequestBody EmpDimissionQo empDimissionQo){
        try {
            employeeWebService.empDimission(empDimissionQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[EmployeeController]---empDeparture--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---empDeparture--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 员工分配账号
     * @param empDistributionAccountQo
     * @return
     */
    @PostMapping("/empDistributionAccount")
    public PlatformResult empDistributionAccount(@Validated @RequestBody EmpDistributionAccountQo empDistributionAccountQo){
        try {
            employeeWebService.empDistributionAccount(empDistributionAccountQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[EmployeeController]---empDistributionAccount--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[EmployeeController]---empDistributionAccount--->Exception:",e);
            return PlatformResult.failure();
        }
    }

}
